﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Caching;
using System.Windows.Forms;

namespace QQyinYue
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<XiHuan> list = new List<XiHuan>();
        yinyuekongzhi yin = new yinyuekongzhi();
        private void button1_Click(object sender, EventArgs e)
        {
            contextMenuStrip1.Items[1].Visible = false;
            contextMenuStrip1.Items[0].Visible =  true;
            List<YinYue> list = new List<YinYue>()
            {
               new YinYue(){Name="老男孩",Zhuchang="筷子兄弟",url="H:\\任务\\音乐\\筷子兄弟 - 老男孩.mp3"},
               new YinYue(){Name="小苹果",Zhuchang="筷子兄弟",url="H:\\任务\\音乐\\筷子兄弟 - 小苹果.mp3"},
               new YinYue(){Name="龙卷风",Zhuchang="周杰伦",url="H:\\任务\\音乐\\龙卷风.mp3"},
               new YinYue(){Name="南山南",Zhuchang="马頔",url="马頔 - 南山南.mp3"},
               new YinYue(){Name="短裙",Zhuchang="AOA",url="H:\\任务\\音乐\\AOA - 短裙.mp3"},
               new YinYue(){Name="一笑而过",Zhuchang="那英",url="H:\\任务\\音乐\\那英 - 一笑而过.mp3"},
               new YinYue(){Name="告白气球",Zhuchang="周杰伦",url="H:\\任务\\音乐\\告白气球.mp3"},
               new YinYue(){Name="喜欢你",Zhuchang="邓紫棋",url="H:\\任务\\音乐\\G.E.M. 邓紫棋 (Gem Tang) - 喜欢你.mp3"}
            };
            BindingSource bindingSource = new BindingSource();
            bindingSource.DataSource = list;
            dataGridView1.DataSource = bindingSource;
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            axWindowsMediaPlayer1.URL = dataGridView1.SelectedRows[0].Cells["Column3"].Value.ToString();
        }

        private void 添加到我喜欢ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string name = dataGridView1.SelectedRows[0].Cells["Column1"].Value.ToString();
            string zhuchang = dataGridView1.SelectedRows[0].Cells["Column2"].Value.ToString();
            string url = dataGridView1.SelectedRows[0].Cells["Column3"].Value.ToString();

            bool bo = ZhaoGe(name,zhuchang);
            if (bo)
            {
                MessageBox.Show("已有此歌曲");
                return;
            }
            else
            {
                AddGequ(name, zhuchang, url);
                yin.Add(list);
                MessageBox.Show("添加成功");
            }
        }
        public bool ZhaoGe(string Name, string zhuchang)
        {
            foreach (XiHuan item in list)
            {
                if (item.Name.Equals(Name) && item.Zhuchang.Equals(zhuchang))
                {
                    return true;
                }
            }
            return false;
        }

        public void AddGequ(string Name, string zhuchang, string url)
        {
            XiHuan xi = new XiHuan();
            xi.Name = Name;
            xi.url = url;
            xi.Zhuchang = zhuchang;
            list.Add(xi);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            BindingSource bindingSource = new BindingSource();
            bindingSource.DataSource = list;
            dataGridView1.DataSource = bindingSource;
                contextMenuStrip1.Items[1].Visible = true;
                contextMenuStrip1.Items[0].Visible = false;
        }
        int sun = 0;
        public bool Delete(string name, string zhuchang)
        {
            try
            {
                ++sun;
                foreach (var item in list)
                {
                    if (item.Name.Equals(name) && item.Zhuchang.Equals(zhuchang))
                    {
                        list.Remove(item);
                        break;
                    }
                }
                return true;
            }
            catch (Exception)
            {

                return false;
            }

        }
        private void 删除此歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string name = dataGridView1.SelectedRows[0].Cells["Column1"].Value.ToString();
            string zhuchang = dataGridView1.SelectedRows[0].Cells["Column2"].Value.ToString();
            bool cheng = Delete(name, zhuchang);
            bool ce = yin.delete(sun);
            if (cheng)
            {
                BindingSource bindingSource = new BindingSource();
                bindingSource.DataSource = list;
                dataGridView1.DataSource = bindingSource;
                axWindowsMediaPlayer1.Ctlcontrols.pause();
                MessageBox.Show("删除成功");
            }
            else
            {
                MessageBox.Show("删除失败");
            }
        }
        int zz = 0;
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (zz == 0)
            {
                axWindowsMediaPlayer1.settings.mute = true;
                toolStripButton1.Text = "静音 ";
                zz = 1;
            }
            else if (zz == 1)
            {
                axWindowsMediaPlayer1.settings.mute = false;
                toolStripButton1.Text = "静音";
                zz = 0;
            }
        }
        int num = 0;
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (num == 0)
            {
                axWindowsMediaPlayer1.Ctlcontrols.pause();
                num = 1;
                toolStripButton2.Text = "播放";
            }
            else
            {
                axWindowsMediaPlayer1.Ctlcontrols.play();
                num = 0;
                toolStripButton2.Text = "暂停";
            }
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
        }
    }
}
